"""
$Id: pykadm5.py 10 2007-12-09 11:17:26Z Iosif69 $

"""

import _pykadm5


class KerberosAdmin:

    def __init__(self,admin_principal,password=None,keytab=None,realm=None,admin_server=None):
	    """
	        admin_principal (required) - Kerberos principal with administrative privileges
                realm (optional), 'EXAMPLE.COM'
    	        admin_server (optional) 'kadmin.example.com:749'
	    """
	    if password:
		raise NotImplementedError, 'Finction not implemented'
	    self.admin_principal = admin_principal
	    self.keytab = keytab
	    self.realm = realm
	    self.admin_server = admin_server
	    
	    """
                self.handle = _pykadm5.init_with_password(admin_principal,password, realm, admin_server)
	    else:
                self.handle = _pykadm5.init_with_keytab(admin_principal,keytab, realm, admin_server)
	    """	

    def chpass_principal(self,target_principal,new_password):
	    """
	         chpass_principal(target_principal,new_password) -> int
	         return value:
	             1 - Success
	             0 - Error
	    """
	    handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
	    return _pykadm5.change_password(handle,target_principal,new_password)


    def delete_principal(self,target_principal):
	    """
	         delete_principal(target_principal) -> int
	         return value:
	            1 -Success
	            0 - Error
	    """
	    handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
	    return _pykadm5.delete_principal(handle,target_principal)

    def flush(self):
    	    """
		 flush() ->int
	         Flush all changes to the Kerberos database, leaving the connection to the Kerberos admin server open
	         return value:
	            1 -Success
	            0 - Error
    	    """
    	    handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
    	    return _pykadm5.flush(handle)
	
	
    def get_principals(self,):
	    """
	         get_principals() -> list
	         Gets all principals from the Kerberos database on False on failure
	    """
            handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
	    return _pykadm5.get_principals(handle)
    
    def modify_principal(self,target_principal,options):
	    """
	         modify_principal(target_principal,options) ->  int
	         return value:
	            1 -Success
	            0 - Error
	    """
	    handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
    	    return _pykadm5.modify_principals(handle,target_principal,options)

    def create_principal(self,principal,password=None,options=None):
            """
	         create_principal(principal,password=None,options=None) -> int
	         return value:
	            1 -Success
	            0 - Error
    	    """
            handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
	    return _pykadm5.create_principal(handle,principal,password,options)

    def get_principal(self,target_principal):
	    """
	         get_principal(target_principal) -> list
	         Gets the principal's entries from the Kerberos database or False on failure
	    """
            handle = _pykadm5.init_with_keytab(self.admin_principal,self.keytab, self.realm, self.admin_server)
	    return _pykadm5.get_principal(handle,principal)
